<template>
	<div :class="{ hidden: hidden }" class="pagination-container">
		<el-pagination
      class="mt15"
			:background="background"
			:current-page.sync="currentPage"
			:page-size.sync="pageSize"
			:layout="layout"
			:page-sizes="pageSizes"
			:total="total"
			@size-change="handleSizeChange"
			@current-change="handleCurrentChange"
		/>
	</div>
</template>

<script setup lang="ts" name="Pagination">
import { computed } from 'vue'
const props = defineProps({
  total: { type: Number, required: true },
  page: { type: Number, required: true, default: 1 },
  limit: { type: Number, required: true, default: 10 },
  pageSizes: { type: Array, required: false, default: () => [10, 20, 30, 50] },
  layout: { type: String, required: false, default: 'total, sizes, prev, pager, next, jumper' },
  background: { type: Boolean, required: false, default: true },
  hidden: { type: Boolean, required: false, default: false },
});

const currentPage = computed({
  get() {
    return props.page
  },
  set(value) {
    emit('update:page', value);
  }
});

const pageSize = computed({
  get() {
    return props.limit
  },
  set(value) {
    emit('update:limit', value);
  }
});

const emit = defineEmits(['update:page', 'update:limit', 'pagination']);

const handleSizeChange = (value: number) => {
  emit('pagination', { page: currentPage, limit: value });
}

const handleCurrentChange = (value: number) => {
  emit('pagination', { page: currentPage, limit: value });
  emit('pagination', { page: value, limit: pageSize });
}
</script>

<style lang="scss" scoped>
.pagination-container {
	background: #fff;
	// padding: 10px 16px;
	padding: 5px 0;
	text-align: right;
}

.pagination-container.hidden {
	display: none;
}
</style>
